import {
	getConfig
} from '@/api/common.js';
import {
	getUserInfo
} from '@/api/user.js';
import {
	settingStore,
	userInfoStore,
	globalConfigStore
} from "@/stores/index.js"
import { getSettingInfo } from '@/api/my';
import tools from './tool.js';

export default () => {
	const setting = settingStore(),
		userInfo = userInfoStore(),
		gc = globalConfigStore()

	getConfig({
		name: 'sys_config_values'
	}).then((res) => {
		res.forEach(item => {
			setting[item.dictLabel] = item.dictValue;
			setting[`${item.dictLabel}_dictExtF`] = item.dictExtF
			setting[`${item.dictLabel}_remark`] = item.remark
		});
		console.log(setting.force_update);
		// 升级检查
		const token = uni.getStorageSync('token');
		if (token) getSettingInfo().then(res => {
			tools.checkUpdate(res, 0, setting.force_update)
		});
	});
	getConfig({
		name: 'sys_user_sex'
	}).then((res) => {
		setting['sys_user_sex'] = res;
	});
	getConfig({
		name: 'his_average'
	}).then((res) => {
		res.forEach((item, index) => {
			if (!gc.score[index]) gc.score[index] = {};
			gc.score[index].label = item.dictLabel;
			gc.score[index].code = item.dictCode;
			gc.score[index].remark = item.remark;
		});
	});

	const token = uni.getStorageSync('token');
	if (token) {
		getUserInfo().then((res) => {
			Object.assign(userInfo, res);
		});
	}
}